package com.soma.game.service.impl;

import com.soma.game.entity.Game;
import com.soma.game.entity.GameExample;
import com.soma.game.enums.BooleanStatus;
import com.soma.game.enums.GameStaticType;
import com.soma.game.enums.GameStatus;
import com.soma.game.mapper.GameExtMapper;
import com.soma.game.mapper.GameMapper;
import com.soma.game.service.GameService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GameServiceImpl extends BaseServiceImpl<GameMapper, Game, GameExample> implements GameService {


    @Resource
    private GameExtMapper gameExtMapper;

    @Override
    public List<Game> getOnlineGames(String language) {
        return gameExtMapper.getOnlineGames(language);
    }

    @Override
    public List<Game> getListByStaticType(GameStaticType gameStaticType) {
        GameExample example = new GameExample();
        example.createCriteria().andActiveFlgEqualTo(BooleanStatus.Y).andStaticTypeEqualTo(gameStaticType);
        return selectByExample(example);
    }

    @Override
    public Game load(Long gameId, String language) {
        List<Game> games = gameExtMapper.getOnlineGames(language);
        return games.stream().filter(game -> game.getId().longValue()==gameId).findFirst().orElse(null);
    }
}